const GetIsLogin = () => {
  try {
    if (localStorage.isLogin != true) {
      return false
    }
    return false

  } catch (e) {
    return false;

  }

}
const GetCurrUserInfo = () => {
  if (sessionStorage.currUserInfo == undefined || sessionStorage.currUserInfo == []) {
    //当前用户信息已经过期
    localStorage.isLogin = false;
    return [];
  }
  return JSON.parse(sessionStorage.currUserInfo);
}
const GetUserList = () => {
  try {
    if (localStorage.userList == undefined) {
      return [];
    }
    return JSON.parse(localStorage.userList) || []

  } catch (e) {
    return [];

  }





}

const SetUserList = (state) => {
  localStorage.userList = JSON.stringify(state.userList);

}
export default {
  namespaced: true,
  state: {
    isLogin: GetIsLogin(),
    userList: GetUserList(),
    currUserInfo: GetCurrUserInfo(),


  },
  mutations: {
    SetUserInfo(state, payload) {
      console.log(payload.user)
      state.userList.push(payload.user);
      SetUserList(state);
    },
    //设置登陆状态
    UpdateLoginStatus(state, payload) {
      console.log(payload.isLogin);
      console.log(payload.user)
      state.isLogin = payload.isLogin;
      if (payload.isLogin) {

        sessionStorage.setItem('currUserInfo', JSON.stringify(payload.user))
      } else {
        //注销登陆
        if (sessionStorage.getItem('currUserInfo') != undefined)
          sessionStorage.removeItem('currUserInfo');

      }
      localStorage.isLogin = payload.isLogin;


    }

  },
  actions: {

  },
  getters: {

  }

}
